package cn.darksoul3.springcloud.core.api;

import cn.darksoul3.common.result.GlobalCodeMsgEnum;
import cn.darksoul3.common.result.ObjectResult;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Component;

@Component
public class TickFallbackSvc implements TickSvc {


    @Override
    @HystrixCommand()
    public ObjectResult tick() {
        return ObjectResult.fail(GlobalCodeMsgEnum.FAIL_TOUT);
    }

    @Override
    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000")
    public ObjectResult tout() throws InterruptedException {
        return ObjectResult.fail(GlobalCodeMsgEnum.FAIL);
    }

    @Override
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "circuitBreaker.enabled",value = "true"),
            @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage",value = "60"),
            @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold",value = "10"),
            @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds",value = "10000")
    })
    public ObjectResult tBreak(Integer id) {
        return ObjectResult.fail(GlobalCodeMsgEnum.SVC_BREAK);
    }
}
